/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tuyenmonkey.samples;

import com.tuyenmonkey.textdecorator.TextDecorator;

import com.tuyenmonkey.textdecorator.callback.OnTextClickListener;

import ohos.aafwk.ability.Ability;

import ohos.aafwk.content.Intent;

import ohos.agp.components.Component;

import ohos.agp.components.Text;

import ohos.agp.utils.Color;

import ohos.agp.window.dialog.ToastDialog;

import ohos.agp.window.service.WindowManager;

/**
 * MainAbility
 */
public class MainAbility extends Ability {
    /**
     * onStart
     * @param intent intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
        setUIContent(ResourceTable.Layout_ability_main);

        Text tvContent = (Text) findComponentById(ResourceTable.Id_tvContent);
        final String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et porta ipsum. " +
                "Praesent vitae libero a mi sodales accumsan. Donec tempor nulla turpis, vitae pellentesque " +
                "ligula consectetur sed. Quisque commodo lorem eget ipsum pulvinar consequat. Nam erat risus, " +
                "rhoncus quis ligula sed, tempor venenatis nulla. Duis quis placerat quam.";
        TextDecorator
                .decorate(tvContent, text, false)
                .setTextColor(Color.argb(255, 255, 64, 129), "Lorem", "amet")
                .strikethrough("Duis", "Praesent")
                .underline("sodales", "quam")
                .setSubscript("vitae")
                .makeTextClickable(new OnTextClickListener() {
                    @Override
                    public void onClick(Component view, String text) {
                        new ToastDialog(getContext()).setText("porta").show();
                    }
                }, "porta")
                .makeTextClickable(new OnTextClickListener() {
                    @Override
                    public void onClick(Component view, String text) {
                        new ToastDialog(getContext()).setText("commodo").show();
                    }
                }, "commodo")
                .makeTextClickable(new OnTextClickListener() {
                    @Override
                    public void onClick(Component view, String text) {
                        new ToastDialog(getContext()).setText("tempor venenatis nulla").show();
                    }
                }, "tempor venenatis nulla")
                .setTextColor(Color.argb(255, 153, 204, 0), "porta", "commodo", "tempor venenatis nulla")
                .build();
    }

    /**
     * onStop
     */
    @Override
    public void onStop() {
        super.onStop();
    }
}
